package cn.edu.sjtu.se.dslab.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.sjtu.se.dslab.action.bean.PageBean;
import cn.edu.sjtu.se.dslab.component.data.DomainEntity;
import cn.edu.sjtu.se.dslab.dao.IDomainEntityDao;
import cn.edu.sjtu.se.dslab.exception.DBException;
import cn.edu.sjtu.se.dslab.service.IDomainEntityService;

@Service("domainEntityService")
@Transactional
public class DomainEntityServiceImpl implements IDomainEntityService {

	@Resource(name = "domainEntityDao")
	private IDomainEntityDao domainEntityDao;

	@Override
	public boolean addDomainEntity(DomainEntity entity) {
		// TODO Auto-generated method stub
		domainEntityDao.save(entity);
		return true;
	}

	@Override
	public DomainEntity getDomainEntityById(long id) {
		// TODO Auto-generated method stub
		return domainEntityDao.queryById(id);
	}

	@Override
	public boolean updateDomainEntity(DomainEntity entity) {
		// TODO Auto-generated method stub
		domainEntityDao.update(entity);
		return true;
	}

	@Override
	public PageBean<DomainEntity> getPageBean(int pageNo) throws DBException {
		// TODO Auto-generated method stub
		return domainEntityDao.queryByPageNum(pageNo);
	}

	@Override
	public DomainEntity getDomainEntityByUri(String uri) {
		// TODO Auto-generated method stub
		return domainEntityDao.queryByUri(uri);
	}

	@Override
	public List<DomainEntity> getAllDomainEntity() {
		// TODO Auto-generated method stub
		return domainEntityDao.queryAll();
	}

	@Override
	public PageBean<DomainEntity> getDataEntityPageBean(int pageNo)
			throws DBException {
		// TODO Auto-generated method stub
		return domainEntityDao.queryDataEntityByPageNum(pageNo);
	}

	@Override
	public List<DomainEntity> getDomainEntityByText(String text) {
		// TODO Auto-generated method stub
		return domainEntityDao.queryByProperty(text);
	}

	@Override
	public DomainEntity getDomainEntityByName(String text) {
		// TODO Auto-generated method stub
		return domainEntityDao.queryByName(text);
	}

}
